//
//  HomeCell.swift
//  CustomSwiftProject
//
//  Created by 岚海网络 on 2019/4/9.
//  Copyright © 2019 ljm. All rights reserved.
//

import UIKit

class HomeCell: UITableViewCell {

    var imageV : UIImageView!
    var titleLab : UILabel!
    var iconV : UIImageView!
    var nameLab : UILabel!
    var contentLab : UILabel!
    
    var model : HomeModel!{
        didSet {
            imageV.image = self.model!.imageV
            titleLab.text = self.model!.title
            iconV.image = self.model!.icon
            nameLab.text = self.model!.name
            contentLab.text = self.model!.content
        }
    }
    
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        createWithUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    func createWithUI() {
        
        imageV = UIImageView.init()
        contentView.addSubview(imageV)
        imageV.snp.makeConstraints{
            $0.top.equalTo(contentView.snp_top).offset(12)
            $0.left.equalTo(contentView.snp_left).offset(8)
            $0.right.equalTo(contentView.snp_right).offset(-8)
            $0.height.equalTo(160)
        }
        
        titleLab = UILabel.init()
        titleLab.backgroundColor = .white
        titleLab.textColor = .black
        titleLab.textAlignment = .left
        titleLab.font = .systemFont(ofSize: 15)
        contentView.addSubview(titleLab)
        titleLab?.snp.makeConstraints{
            $0.top.equalTo(imageV.snp_bottom).offset(5)
            $0.left.equalTo(imageV.snp_left)
        }
        
        
        nameLab = UILabel.init()
        nameLab.backgroundColor = .white
        nameLab.textColor = .black
        nameLab.textAlignment = .right
        nameLab.font = .systemFont(ofSize: 15)
        contentView.addSubview(nameLab)
        nameLab?.snp.makeConstraints{
            $0.centerY.equalTo(titleLab.snp_centerY)
            $0.right.equalTo(imageV.snp_right)
            $0.width.equalTo(100)
        }
        
        iconV = UIImageView.init()
        contentView.addSubview(iconV)
        iconV.snp.makeConstraints{
            $0.right.equalTo(nameLab.snp_left).offset(3)
            $0.centerY.equalTo(nameLab.snp_centerY)
            $0.width.height.equalTo(20)
        }
        
        
        contentLab = UILabel.init()
        contentLab.backgroundColor = .white
        contentLab.textColor = .black
        contentLab.textAlignment = .left
        contentLab.numberOfLines = 0
        contentLab.font = .systemFont(ofSize: 14)
        contentView.addSubview(contentLab)
        contentLab?.snp.makeConstraints{
            $0.top.equalTo(titleLab.snp_bottom).offset(5)
            $0.left.equalTo(contentView.snp_left).offset(8)
            $0.bottom.right.equalTo(contentView).offset(-8)
        }
        
    }
    
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    
}
